/*
 * <p>Copyright ®Alyce_WX版权所有。</p>
 * 类名:RoleDaoImpl
 * 创建人:alyce_wx
 * 创建时间:2017-03-30
 */

package com.wx.demo.wcd.infrastructure.dao.impl;

import java.util.Map;

import javax.annotation.Resource;

import org.mybatis.spring.SqlSessionTemplate;
import org.springframework.stereotype.Repository;

import com.wx.demo.wcd.domain.pk.RolePK;
import com.wx.demo.wcd.domain.po.RolePO;
import com.wx.demo.wcd.domain.qo.RoleQO;
import com.wx.demo.wcd.infrastructure.dao.RoleDao;
import com.yjhl.framework.dao.AbstractDao;

/**
 * RoleDAO implement
 *
 * @author alyce_wx
 * @see com.yjhl.framework.dao.AbstractDao
 * @see com.wx.demo.wcd.infrastructure.dao.RoleDao;
 * @since 1.8
 * @version 1.0.0
 */
 
@Repository("roleDao")
public class RoleDaoImpl extends AbstractDao<RolePO, RoleQO, RolePK> implements RoleDao {
    /**
	 * spring SQL session
	 */
    @Resource
    private SqlSessionTemplate wcdSqlSessionTemplate;
	
	/**
	 * Get SQL session。 Get SQL session since spring auto wired.
	 *
	 * @return SQL session
	 * @see com.yjhl.framework.dao.AbstractDAO#getSqlSessionTemplate()
	 * @since 1.8
	 * @version 1.0.0
	 */
    @Override
    protected SqlSessionTemplate getSqlSessionTemplate() {
        return wcdSqlSessionTemplate;
    }
	
	/**
	 * 获取mybatis的命名空间。
	 *
	 * @return MyBatis的命名空间.
	 * @see com.yjhl.framework.dao.AbstractDAO#getNamespace()
	 * @since 1.8
	 * @version 1.0.0
	 */
    @Override
    protected String getNamespace() {
        return "wcdroleDAO";
    }
    
     /**
	 * 获取不带"-"的UUID。
	 *
	 * @return 不带"-"的UUID.
	 * @see com.yjhl.framework.dao.AbstractDao#getSequence()
	 * @since 1.8
	 * @version 1.0.0
	 */
    @Override
    public String getSequence()  {
    		return getSequenceUUID("role");
		
    }
    
    /**
	 * 插入单条数据。 如果entity的属性值为null或空，该属性对应的列将不会被插入。
	 *
	 * @param entity 插入的内容.
	 * @return 插入记录条数
	 * @see com.yjhl.framework.dao.AbstractDao#insert(com.yjhl.framework.domain.po.PO)
	 * @since 1.8
	 * @version 1.0.0
	 */
	@Override
    public int insert(RolePO entity) {
		if(null == entity.getRoleId() || "".equals(entity.getRoleId())){
			entity.setRoleId(getSequenceUUID("role"));
		}
    	
    	return super.insert(entity);
    }
    
    /**
	 * @see RoleDao#getByPk(String)
	 */
	@Override
	public RolePO getByPk(String roleId){
		RolePK entityPK = new RolePK( roleId );
    	
    	return super.getByPk( entityPK );
	}	
	/**
	 * @see RoleDao#updateMapByPk(Map, String)
	 */
	@Override
	public int updateMapByPk(Map<String,Object> entity, String roleId){
		RolePK entityPK = new RolePK( roleId );
		
		return super.updateMapByPk(entity, entityPK );
	}	
	/**
	 * @see RoleDao#deleteByPk(String)
	 */
	@Override
	public int deleteByPk(String roleId){
		RolePK entityPK = new RolePK( roleId );
		
		return super.deleteByPk( entityPK );
	}	
    
}
